/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Form = require("form");
	var scatterCheckInSvc = require("../service/scatterCheckInSvc");
	var processData = require("../store/processData");
	var ScatterCheckInRoomForm = require("../component/ScatterCheckInRoomForm");
	var scatterCheckInBiz = require("../business/scatterCheckInBiz");
	
    var instance = {
        initComponent: function (params,widget) {
        	var doorForm = new Form({
        		parentNode: ".J-doorForm",
        		model: {
        			id: "doorForm",
        			layout: "3_1",
        			defaultButton : false,
        			items: [{
        				name: "servicePoint",
						label: "目的地",
						readonly: true
        			},{
        				name: "pkServicePoint",
        				type: "hidden"
        			},{
        				name: "checkInDate",
						label: "入住日期",
						type: "date",
						mode:"YYYY-MM-DD",
						defaultValue:moment().format("YYYY-MM-DD"),
        			},{
        				name: "checkOutDate",
						label: "退住日期",
						type: "date",
						mode:"YYYY-MM-DD",
						onSelectDate:function(timeData){
                			$(".J-forms").empty()
                			var pkCIImplement = doorForm.getValue("pkCIImplement");
            				var data = widget.get("tempGridRowData");
            				if(!data){
            					return;
            				}
            				
            				var saleDate = doorForm.getValue("checkInDate"),
                       			saleDateEnd = timeData.getTime(),
                       			roomTypes = data.nonMemGroupReserve.signUpRooms,
                    			nonMemberType = scatterCheckInBiz.nonMemberTypeS(data,widget),
                    			arr = [];
                    		for(var k=0;k<roomTypes.length;k++){
                    			arr.push(roomTypes[k].roomType.pkRoomType);
                    		}
                    		var pkOrgBuildingIn = [];
                    		
                    		for(var i=0;i<data.roomPersonalInfos.length;i++){
                    			var info = data.roomPersonalInfos[i];
                    			if(info.roomRegister.room){
                    				pkOrgBuildingIn.push(info.roomRegister.room.orgBuilding.pkOrgBuilding);	
                    			}
                    		}
	                    		
                     		var cParams = {
                     			"saleDate":saleDate,
                     			"saleDateEnd":saleDateEnd,
                     			"roomType.pkRoomTypeIn":arr.join(","),
                     			"orgBuilding.pkOrgBuildingIn":pkOrgBuildingIn.join(",")==""?null:pkOrgBuildingIn.join(","),
                     			fetchProperties:"orgBuilding.pkOrgBuilding,standardPrice,vipPrice,protocolPrice,pkRoomTypePrice,roomType.*,saleDate"
                     		};
                     		
                     		scatterCheckInSvc.queryRoomTypePrice(cParams,function(ret){
                     			var roomPriceData = processData.roomPriceData(widget,ret);
                				ScatterCheckInRoomForm.renderForm(widget,nonMemberType,roomPriceData,roomTypes);  	
                				$(".el-checkradio").hide();
                    		});
                       	 }
        			},{
        				name: "description",
						label: "备注",
						readonly: true
        			},{
        				name:"dataSource",
        				type:"hidden",
        				defaultValue:"VisitDoorFIT"
        			},{
        				name:"signUpType",
        				type:"hidden"
        			},{
        				name:"sourceType",
        				type:"hidden"
        			},{
        				name: "version",
						type: "hidden",
						defaultValue: "0"
        			},{
        				name:"pkCIImplement",
        				type:"hidden"
        			},{
        				name:"pkNonMemGroupReserve",
        				type:"hidden"
        			},{
        				name:"versionNonMemGroupReserve",
        				type:"hidden",
						defaultValue: "0"
        			},{
        				name:"pkNonMemberGroup",
        				type:"hidden"
        			},{
        				name:"versionNonMemberGroup",
        				type:"hidden",
						defaultValue: "0"
        			},{
        				name:"statusNonMemberGroup",
        				type:"hidden"
        			},{
        				name:"status",
        				type:"hidden"
        			},{
        				name:"statementStatus",
        				type:"hidden"
        			},{
        				name:"roomStatus",
        				type:"hidden"
        			}]
        		}
        	});
        	widget.set("doorForm",doorForm);
        }
    };
    module.exports = instance;
});
